
$(function() {
    validateKickout2();
    validateRule2();
    $('.imgcode2').click(function() {
        var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
        $(".imgcode2").attr("src", url);
    });
});

$.validator.setDefaults({
    submitHandler: function() {
       if(currentLogin == '1'){
           login();
       }else if(currentLogin == '2'){
           login2();
       }else if(currentLogin == '3'){
           login3();
       }
    }
});

function login2() {
    $.modal.loading($("#btnSubmit2").data("loading"));
    var username = $.common.trim($("input[name='username2']").val());
    var password = $.common.trim($("input[name='password2']").val());
    var validateCode = $("input[name='validateCode2']").val();
    var rememberMe = $("input[name='rememberme2']").is(':checked');
    $.ajax({
        type: "post",
        url: ctx + "login",
        data: {
            "username": username,
            "password": password,
            "validateCode": validateCode,
            "rememberMe": rememberMe
        },
        success: function(r) {
            if (r.code == web_status.SUCCESS) {
                location.href = ctx + 'index';
            } else {
            	$('.imgcode2').click();
            	$(".code2").val("");
            	$.modal.msg(r.msg);
            }
            $.modal.closeLoading();
        }
    });
}

function validateRule2() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm2").validate({
        rules: {
            username2: {
                required: true
            },
            password2: {
                required: true
            }
        },
        messages: {
            username2: {
                required: icon + "请输入您的用户名",
            },
            password2: {
                required: icon + "请输入您的密码",
            }
        }
    })
}

function validateKickout2() {
    if (getParam("kickout") == 1) {
        layer.alert("<font color='red'>您已在别处登录，请您修改密码或重新登录</font>", {
            icon: 0,
            title: "系统提示"
        },
        function(index) {
            //关闭弹窗
            layer.close(index);
            if (top != self) {
                top.location = self.location;
            } else {
                var url = location.search;
                if (url) {
                    var oldUrl = window.location.href;
                    var newUrl = oldUrl.substring(0, oldUrl.indexOf('?'));
                    self.location = newUrl;
                }
            }
        });
    }
}
